package com.shuma.shopmanage.common.exception;

import com.shuma.shopmanage.common.result.Result;
import com.shuma.shopmanage.common.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ShopManageException.class)
    @ResponseBody
    public Result error(ShopManageException e) {
        e.printStackTrace();
        return Result.build(e.getCode(),e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result error(RuntimeException e) {
        e.printStackTrace();
        return Result.build(null, ResultCodeEnum.SERVICE_ERROR);
    }



}
